/*
2021-10-17
https://www.acwing.com/problem/content/4000/
*/ 
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    
    int t;
    cin>>t;
    while(t--)
    {
        int k,l;
        cin>>k>>l;
        bool flag=true;
        while(l>1)
        {
            if(l%k) flag=false;
            l/=k;
        }
        if(flag) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    
    return 0;
}
